package com.lovi.io_;

import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 自己完成文件复制，注意是图片!！
 * 思路，从输入流read字节过来，然后通过输出流写出去
 */
public class FileCopy01 {
    @Test
    public void test() throws Exception{
        String filePath = "D:\\Pictures\\coding_img\\1.png";
        File file = new File(filePath);
        FileInputStream inputStream = new FileInputStream(file);
        FileOutputStream outputStream = new FileOutputStream("D:\\Pictures\\coding_img\\3.png");
        int readData = 0;
        byte[] b = new byte[1024];
        while ((readData = inputStream.read(b))!=-1){
            //边读取边写
            outputStream.write(b,0,readData);
        }
        if(outputStream!=null){
            outputStream.close();
        }
        if(inputStream!=null){
            outputStream.close();
        }
        System.out.println("复制成功");

    }

}
